package org.road0329.tools.proto_parse_tool.ems.qgdw3761.utils;

import org.road0329.tools.proto_parse_tool.chargingpile.MsgDcsResult;
import org.road0329.tools.proto_parse_tool.ems.dataobject.gw.GwItemData;
import org.road0329.tools.proto_parse_tool.ems.dataobject.gw.ReqDataComm;
import org.road0329.tools.proto_parse_tool.ems.dataobject.gw.afn0C.Req1stDataF188;
import org.road0329.tools.proto_parse_tool.ems.dataobject.gw.afn0D.Req2ndDataParam;
import org.road0329.tools.proto_parse_tool.enums.DateFormatEnum;
import org.road0329.tools.proto_parse_tool.enums.MeterTypeEnum;
import org.road0329.tools.proto_parse_tool.enums.UnitCodeEnum;
import org.road0329.tools.proto_parse_tool.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018-09-20.
 */
@Component
public class Gw09ClassTwoUtil {
    private static final int TARIFF_NUM_DEFAULT = 4;// 目前集中器按费率数=4 上送任务数据

    private static Logger logger = LoggerFactory.getLogger(Gw09ClassTwoUtil.class);

    public static MsgDcsResult parseClassTwoData(byte[] msg, int from, boolean acd) throws Exception {
        String commAddr = String.format("%02X%02X%02X%02X", msg[8], msg[7], msg[10], msg[9]);
        int index = from;
        int fixlen = (msg[index] & 0x80) == 0 ? 2 : 8;
        if (acd) {
            fixlen += 2;
        }
        index++;
        MsgDcsResult gwResult = new MsgDcsResult();
        List<GwItemData> gwItemList = new ArrayList<GwItemData>();
        List<Integer> pnList;
        while ((index + fixlen) < msg.length) {
            pnList = ProtocolGW_09Util.getPnListFromDA(msg[index + 1], msg[index]);
            int fn = ProtocolGW_09Util.getFnFromDT(msg[index + 3], msg[index + 2]);
            index += 4;
            for (Integer pn : pnList) {
                GwItemData item = new GwItemData();
                item.setFn(fn);
                item.setPn(pn);
                ReqDataComm reqDataComm;
                int n;
                switch (fn) {
                    case 1:
                    case 2:
                        reqDataComm = parseF1F2Frame(msg, index, fn);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 8]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 8 + 1 + (n + 1) * 5 + (n + 1) * 4 * 3;
                        break;
                    case 3:
                    case 4:
                        if (fn == 3) {
                            reqDataComm = parseF3F4Frame(msg, index, "正向");
                        } else {
                            reqDataComm = parseF3F4Frame(msg, index, "反向");
                        }
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 8]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 8 + 1 + (n + 1) * 7 * 2;
                        break;
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                        if (fn == 5) {
                            reqDataComm = parseF5678Frame(msg, fn, "正向有功");
                        } else if (fn == 6) {
                            reqDataComm = parseF5678Frame(msg, fn, "正向无功");
                        } else if (fn == 7) {
                            reqDataComm = parseF5678Frame(msg, fn, "反向有功");
                        } else {
                            reqDataComm = parseF5678Frame(msg, fn, "反向无功");
                        }
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 3]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 3 + 1 + (n + 1) * 4;
                        break;
                    case 17:
                    case 18:
                        if (fn == 17) {
                            reqDataComm = parseF1718Frame(msg, index, "正向");
                        } else {
                            reqDataComm = parseF1718Frame(msg, index, "反向");
                        }
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 7]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 7 + 1 + (n + 1) * 5 + (n + 1) * 4 * 3;
                        break;
                    case 27:
                        reqDataComm = parseF27Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 69;
                        break;
                    case 28:
                        reqDataComm = parseF28Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 17;
                        break;
                    case 29:
                        reqDataComm = parseF29Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 41;
                        break;
                    case 30:
                        reqDataComm = parseF30Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 7;
                        break;
                    case 31:
                        reqDataComm = parseF31Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 13;
                        break;
                    case 32:
                        reqDataComm = parseF32Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 60;
                        break;
                    case 81:
                    case 82:
                    case 83:
                    case 84:
                        reqDataComm = parseF81234Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 3;
                        break;
                    case 85:
                    case 86:
                    case 87:
                    case 88:
                        reqDataComm = parseF85678Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 3;
                        break;
                    case 89:
                    case 90:
                    case 91:
                        reqDataComm = parseF8991Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 2;
                        break;
                    case 92:
                    case 93:
                    case 94:
                    case 95:
                        reqDataComm = parseF9295Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 3;
                        break;
                    case 97:
                    case 98:
                    case 99:
                    case 100:
                    case 101:
                    case 102:
                    case 103:
                    case 104:
                        if (fn == 97) {
                            reqDataComm = parseF97100Frame(msg, index, "正向有功总电能量");
                        } else if (fn == 98) {
                            reqDataComm = parseF97100Frame(msg, index, "正向无功总电能量");
                        } else if (fn == 99) {
                            reqDataComm = parseF97100Frame(msg, index, "反向有功总电能量");
                        } else if (fn == 100) {
                            reqDataComm = parseF97100Frame(msg, index, "反向无功总电能量");
                        } else if (fn == 101) {
                            reqDataComm = parseF101104Frame(msg, index, "正向有功总电能示值");
                        } else if (fn == 102) {
                            reqDataComm = parseF101104Frame(msg, index, "正向无功总电能示值");
                        } else if (fn == 103) {
                            reqDataComm = parseF101104Frame(msg, index, "反向有功总电能示值");
                        } else {
                            reqDataComm = parseF101104Frame(msg, index, "反向无功总电能示值");
                        }
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 4;
                        break;
                    case 105:
                    case 106:
                    case 107:
                    case 108:
                        reqDataComm = parseF105108Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 2;
                        break;
                    case 109:
                        reqDataComm = parseF109Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 6;
                        break;
                    case 110:
                        reqDataComm = parseF110Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 6]);
                        index += 6 + 1 + n * 6;
                        break;
                    case 161:
                    case 162:
                    case 163:
                    case 164:
                        if (fn == 161) {
                            reqDataComm = parseF161Frame(msg, index);
                        } else if (fn == 162) {
                            reqDataComm = parseF162Frame(msg, index);
                        } else if (fn == 162) {
                            reqDataComm = parseF163Frame(msg, index);
                        } else {
                            reqDataComm = parseF164Frame(msg, index);
                        }
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 8]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        if (fn == 161 || fn == 163) {
                            index += 8 + 1 + (n + 1) * 5;
                        } else {
                            index += 8 + 1 + (n + 1) * 4;
                        }
                        break;
                    case 169:
                        reqDataComm = parseF169Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 8]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 8 + 1 + (n + 1) * 5;
                        break;
                    case 171:
                        reqDataComm = parseF171Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 8]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 8 + 1 + (n + 1) * 5;
                        break;
                    case 170:
                    case 172:
                    case 173:
                    case 174:
                        if (fn == 170) {
                            reqDataComm = parseF170174Frame(msg, index, "日冻结正向无功（组合无功1）电能示值");
                        } else if (fn == 172) {
                            reqDataComm = parseF170174Frame(msg, index, "日冻结反向无功（组合无功1）电能示值");
                        } else if (fn == 173) {
                            reqDataComm = parseF170174Frame(msg, index, "日冻结一象限无功电能示值");
                        } else {
                            reqDataComm = parseF170174Frame(msg, index, "日冻结二象限无功电能示值");
                        }
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 8]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 8 + 1 + (n + 1) * 4;
                        break;
                    case 185:
                    case 186:
                    case 187:
                    case 188:
                        if (fn == 185) {
                            reqDataComm = parseF185188Frame(msg, index, "正向有功");
                        } else if (fn == 186) {
                            reqDataComm = parseF185188Frame(msg, index, "正向无功");
                        } else if (fn == 187) {
                            reqDataComm = parseF185188Frame(msg, index, "反向有功");
                        } else {
                            reqDataComm = parseF185188Frame(msg, index, "反向无功");
                        }
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        n = ProtocolUtils.Unsignd(msg[index + 8]);
                        if (n == 0 || n > 96) {
                            n = TARIFF_NUM_DEFAULT;
                        }
                        index += 8 + 1 + (n + 1) * 7;
                        break;
                    case 220:
                        reqDataComm = parseF220Frame(msg, index);
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 5;
                        break;
                    case 221:
                        reqDataComm = parseF221Frame(msg, index);//新天平台数据上报， 移除havingTask检查
                        item.setData(reqDataComm);
                        item.setSuccess(true);
                        index += 52;
                        break;
                    default:
                        throw new Exception("376.1协议处理==> 二类类数据中找不到PN=" + pn + "FN=" + fn + "的处理方法");
                }
                gwItemList.add(item);//新天平台数据上报， 移除havingTask检查
            }
        }
        gwResult.setData(gwItemList);
        gwResult.setSuccess(true);
        gwResult.setMessage("成功");
        return gwResult;
    }

    private static ReqDataComm parseF220Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        String unit = "";
        unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
        resultString.append("结算日累积流量:").append(ProtocolGW_09Util.parseA220(byteValue, index) + UnitCodeEnum.getText(unit)).append(";");// 结算日热量
        index = index + 5;
        unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
        resultString.append("结算日热量:").append(ProtocolGW_09Util.parseA220(byteValue, index) + UnitCodeEnum.getText(unit)).append(";");// 结算日热量
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF221Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        Req1stDataF188 f188 = new Req1stDataF188();
        reqDataComm.setData(f188);
        StringBuffer resultString = new StringBuffer("");
        String unit = "";
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        f188.setRtuDataTime(ProtocolGW_09Util.parseDateTime(byteValue, index, DateFormatEnum.A15));
        // HH:mm;
        index = index + 5;
        String type = NumberUtil.num2PadString(ProtocolUtils.Unsignd(byteValue[index++]), 16, 2, "0");
        resultString.append("仪表类型:").append(type).append(";");
        // 10,11,12,13,19,30
        BigDecimal value;
        if (MeterTypeEnum.METER_WATER_COLD.getValue().equals(type) || MeterTypeEnum.METER_WATER.getValue().equals(type) || MeterTypeEnum.METER_WATER_PURE.getValue().equals(type)
                || MeterTypeEnum.METER_WATER_HOT.getValue().equals(type) || MeterTypeEnum.METER_WATER_ELEC.getValue().equals(type) || MeterTypeEnum.METER_GAS.getValue().equals(type)) {
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA220(byteValue, index);
            resultString.append("当前累积流量:").append(value + UnitCodeEnum.getText(unit)).append(";");
            f188.setCurCumulant(value);

            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            value = ProtocolGW_09Util.parseA220(byteValue, index);
            resultString.append("结算日累积流量:").append(value + UnitCodeEnum.getText(unit)).append(";");
            f188.setBillDateCumulant(value);

            index = index + 5;
            index = index + 21;// 保留21个字节

            value = ProtocolGW_09Util.parseA10(byteValue, index);
            f188.setWorkHours(value == null ? null : value.intValue());
            resultString.append("累积工作时间:").append(value).append("h;");// 累积工作时间

            index = index + 3;
            String realTime = ProtocolUtils.getByteToHexStringDesc(byteValue, index, 7, "");
            if (!(realTime.indexOf("0000") == 0
                    || realTime.indexOf("EEEE") == 0 || realTime.indexOf("eeee") == 0
                    || realTime.indexOf("FFFF") == 0 || realTime.indexOf("ffff") == 0)) {
                realTime = ProtocolGW_09Util.parseA32(byteValue, index);
                f188.setRealDataTime(DateUtil.LongStrToDate(realTime));
            } else {
                f188.setRealDataTime(f188.getRtuDataTime());
            }
            resultString.append("实时时间:").append(realTime).append(";");// 实时时间

            index = index + 7;
            String st = String.format("%02X", 0xFF & byteValue[index]);
            if (!(st.equalsIgnoreCase("EE") || st.equalsIgnoreCase("FF"))) {
                int valveStatus = ((byteValue[index]) & 0x03);// 阀门状态
                f188.setPowerStatus((short) valveStatus);
                resultString.append("阀门状态:").append(valveStatus).append(";");

                int u = ((byteValue[index] >> 2) & 0x01);// 电池电压
                f188.setBatteryVoltageStatus((short) u);
                resultString.append("电池电压:").append(u).append(";");
            }
            // 20,21
        } else if (MeterTypeEnum.METER_HEAT_HOT.getValue().equals(type) || MeterTypeEnum.METER_HEAT_COLD.getValue().equals(type)) {
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            resultString.append("结算日热量:").append(ProtocolGW_09Util.parseA220(byteValue, index) + UnitCodeEnum.getText(unit)).append(";");
            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            resultString.append("当前热量:").append(ProtocolGW_09Util.parseA220(byteValue, index) + UnitCodeEnum.getText(unit)).append(";");
            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            resultString.append("热功率:").append(ProtocolGW_09Util.parseA10(byteValue, index) + UnitCodeEnum.getText(unit)).append(";");// 热功率
            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            resultString.append("流量:").append(ProtocolGW_09Util.parseA10(byteValue, index) + UnitCodeEnum.getText(unit)).append(";");// 流量
            index = index + 5;
            unit = StringUtil.AddjustLength(Integer.toHexString(byteValue[index] & 0xFF), 2, "0");
            resultString.append("累积流量:").append(ProtocolGW_09Util.parseA10(byteValue, index) + UnitCodeEnum.getText(unit)).append(";");// 累积流量
            index = index + 5;
            resultString.append("供水温度:").append(ProtocolGW_09Util.parseA31(byteValue, index)).append("℃;");// 供水温度
            index = index + 3;
            resultString.append("回水温度:").append(ProtocolGW_09Util.parseA31(byteValue, index)).append("℃;");// 回水温度
            index = index + 3;
            resultString.append("累积工作时间:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("h;");// 累积工作时间
            index = index + 3;
            resultString.append("实时时间:").append(ProtocolGW_09Util.parseA32(byteValue, index)).append(";");// 实时时间
            index = index + 7;
            int valveStatus = ((byteValue[index]) & 0x03);// 阀门状态
            resultString.append("阀门状态:").append(valveStatus).append(";");
            int u = ((byteValue[index] >> 2) & 0x01);// 电池电压
            resultString.append("电池电压:").append(u).append(";");
        }

        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF185188Frame(byte[] byteValue, int index, String type) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append(type).append("总最大需量:").append(ProtocolGW_09Util.parseA23(byteValue, index)).append("kW;");// 正向有功总最大需量
        index = index + 3;
        resultString.append(type).append("总最大需量发生时间:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 正向有功总最大需量发生时间
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1) + type).append("最大需量:").append(ProtocolGW_09Util.parseA23(byteValue, index)).append("kW;");// 费率i正向有功最大需量;
            index = index + 3;
            resultString.append("费率").append((i + 1) + type).append("总最大需量发生时间:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 费率i正向有功总最大需量发生时间;
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF170174Frame(byte[] byteValue, int index, String type) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append(type + ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 反向无功（组合无功1）总电能示值:100kvarh;
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1) + type + ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i反向有功总电能示值:100kvarh;
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF171Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("反向有功总电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 反向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1)).append("反向有功总电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 费率i反向有功总电能示值:100kWh;
            index = index + 5;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF161Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("正向有功总电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 正向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1)).append("正向有功电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 费率i正向有功电能示值:100kWh;
            index = index + 5;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }


    private static ReqDataComm parseF162Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("正向无功（组合无功1）总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 正向无功（组合无功1）总电能示值:100kvarh;
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1)).append("正向无功（组合无功1）总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i正向无功（组合无功1）总电能示值:100kvarh;
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF163Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("反向有功总电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 反向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1)).append("反向有功电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 费率i反向有功电能示值:100kWh;
            index = index + 5;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF164Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append("反向无功（组合无功1）总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 反向无功（组合无功1）总电能示值:100kvarh;
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1)).append("反向无功（组合无功1）电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i1反向无功（组合无功1）电能示值:100kvarh;
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF169Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("A相正向有功电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// A相正向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("B相正向有功电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// B相正向有功电能示值:100kWh;
        index = index + 5;
        resultString.append("C相正向有功电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// C相正向有功电能示值:100kWh;
        index = index + 5;
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF109Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append("Uab/Ua相位角").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("度;");// Uab/Ua相位角1-n
            index = index + 2;
        }
        for (int i = 0; i < datanum; i++) {
            resultString.append("Ub相位角").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("度;");// Ub相位角1-n
            index = index + 2;
        }
        for (int i = 0; i < datanum; i++) {
            resultString.append("Ucb/Uc相位角").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("度;");// Ucb/Uc相位角1-n
            index = index + 2;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF110Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append("Ia相位角").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("度;");// Ia相位角1-n
            index = index + 2;
        }
        for (int i = 0; i < datanum; i++) {
            resultString.append("Ib相位角").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("度;");// Ib相位角1-n
            index = index + 2;
        }
        for (int i = 0; i < datanum; i++) {
            resultString.append("Ic相位角").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("度;");// Ic相位角1-n
            index = index + 2;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF105108Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append("功率因数").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");// 功率因数1-n
            index = index + 2;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF97100Frame(byte[] byteValue, int index, String type) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append(type + (i + 1)).append(":").append(ProtocolGW_09Util.parseA13(byteValue, index)).append(";");// 正向有功电能量1-n
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF101104Frame(byte[] byteValue, int index, String type) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append(type + (i + 1)).append(":").append(ProtocolGW_09Util.parseA11(byteValue, index)).append(";");// 正向有功电能量1-n
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF9295Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append("电流").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// A相电流1-n
            index = index + 3;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF8991Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append("电压").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// A相电压1-n
            index = index + 2;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF85678Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            index = index + 3;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF81234Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("曲线类数据时标:").append(curveData(byteValue, index));
        index = index + 6;
        int datanum = ProtocolUtils.Unsignd(byteValue[index++]);// 数据点数n
        for (int i = 0; i < datanum; i++) {
            resultString.append("有功功率").append((i + 1)).append(":").append(ProtocolGW_09Util.parseA9(byteValue, index)).append("kW;");// 有功功率1-n
            index = index + 3;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF27Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("A相电压越上上限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// A相电压越上上限日累计时间
        index = index + 2;
        resultString.append("A相电压越下下限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// A相电压越下下限日累计时间
        index = index + 2;
        resultString.append("A相电压越上限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// A相电压越上限日累计时间
        index = index + 2;
        resultString.append("A相电压越下限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// A相电压越下限日累计时间
        index = index + 2;
        resultString.append("A相电压合格日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// A相电压合格日累计时间
        index = index + 2;
        resultString.append("B相电压越上上限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// B相电压越上上限日累计时间
        index = index + 2;
        resultString.append("B相电压越下下限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// B相电压越下下限日累计时间
        index = index + 2;
        resultString.append("B相电压越上限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// B相电压越上限日累计时间
        index = index + 2;
        resultString.append("B相电压越下限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// B相电压越下限日累计时间
        index = index + 2;
        resultString.append("B相电压合格日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// B相电压合格日累计时间
        index = index + 2;
        resultString.append("C相电压越上上限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// C相电压越上上限日累计时间
        index = index + 2;
        resultString.append("C相电压越下下限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// C相电压越下下限日累计时间
        index = index + 2;
        resultString.append("C相电压越上限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// C相电压越上限日累计时间
        index = index + 2;
        resultString.append("C相电压越下限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// C相电压越下限日累计时间
        index = index + 2;
        resultString.append("C相电压合格日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// C相电压合格日累计时间
        index = index + 2;
        resultString.append("A相电压最大值:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// A相电压最大值
        index = index + 2;
        resultString.append("A相电压最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// A相电压最大值发生时间
        index = index + 3;
        resultString.append("A相电压最小值:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// A相电压最小值
        index = index + 2;
        resultString.append("A相电压最小值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// A相电压最小值发生时间
        index = index + 3;
        resultString.append("B相电压最大值:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// B相电压最大值
        index = index + 2;
        resultString.append("B相电压最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// A相电压最小值发生时间
        index = index + 3;
        resultString.append("B相电压最小值:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// B相电压最小值
        index = index + 2;
        resultString.append("B相电压最小值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// B相电压最小值发生时间
        index = index + 3;
        resultString.append("C相电压最大值:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// C相电压最大值
        index = index + 2;
        resultString.append("C相电压最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// C相电压最大值发生时间
        index = index + 3;
        resultString.append("C相电压最小值:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// C相电压最小值
        index = index + 2;
        resultString.append("C相电压最小值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// C相电压最小值发生时间
        index = index + 3;
        resultString.append("A相平均电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// A相平均电压
        index = index + 2;
        resultString.append("B相平均电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// B相平均电压
        index = index + 2;
        resultString.append("C相平均电压:").append(ProtocolGW_09Util.parseA7(byteValue, index)).append("V;");// C相平均电压
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF28Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("电流不平衡度越限日累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// 电流不平衡度越限日累计时间
        index = index + 2;
        resultString.append("电压不平衡度越限日累计时间 :").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// 电压不平衡度越限日累计时间
        index = index + 2;
        resultString.append("电流不平衡最大值 :").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");// 电压不平衡度越限日累计时间
        index = index + 2;
        resultString.append("电流不平衡最大值发生时间 :").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// 电流不平衡最大值发生时间
        index = index + 3;
        resultString.append("电压不平衡最大值 :").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");// 电压不平衡最大值
        index = index + 2;
        resultString.append("电压不平衡最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// 电压不平衡最大值发生时间
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF29Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("A相电流越上上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// A相电流越上上限累计时间
        index = index + 2;
        resultString.append("A相电流越上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// A相电流越上限累计时间
        index = index + 2;
        resultString.append("B相电流越上上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// B相电流越上上限累计时间
        index = index + 2;
        resultString.append("B相电流越上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// B相电流越上限累计时间
        index = index + 2;
        resultString.append("C相电流越上上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// C相电流越上上限累计时间
        index = index + 2;
        resultString.append("C相电流越上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// C相电流越上限累计时间
        index = index + 2;
        resultString.append("零序电流越上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// 零序电流越上限累计时间
        index = index + 2;
        resultString.append("A相电流最大值:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// A相电流最大值
        index = index + 3;
        resultString.append("A相电流最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// A相电流最大值发生时间
        index = index + 3;
        resultString.append("B相电流最大值:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// B相电流最大值
        index = index + 3;
        resultString.append("B相电流最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// B相电流最大值发生时间
        index = index + 3;
        resultString.append("C相电流最大值:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// C相电流最大值
        index = index + 3;
        resultString.append("C相电流最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append(";");// C相电流最大值发生时间
        index = index + 3;
        resultString.append("零序电流最大值:").append(ProtocolGW_09Util.parseA25(byteValue, index)).append("A;");// 零序电流最大值
        index = index + 3;
        resultString.append("零序电流最大值发生时间:").append(ProtocolGW_09Util.parseA18(byteValue, index)).append("A;");// 零序电流最大值发生时间
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF30Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("视在功率越上上限累计时间:").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// 视在功率越上上限累计时间
        index = index + 2;
        resultString.append("视在功率越上限累计时间 :").append(ProtocolUtils.byteToShort(byteValue[index + 1], byteValue[index])).append("min;");// 视在功率越上限累计时间
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF31Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("负载率最大值:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");// 负载率最大值
        index = index + 2;
        resultString.append("负载率最大值发生时间:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");// 负载率最大值发生时间
        index = index + 3;
        resultString.append("负载率最小值:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append("%;");// 负载率最小值
        index = index + 2;
        resultString.append("负载率最小值发生时间:").append(ProtocolGW_09Util.parseA5(byteValue, index)).append(";");// 负载率最小值发生时间
        index = index + 3;
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF32Frame(byte[] byteValue, int index) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        resultString.append("总断相次数:").append(ProtocolGW_09Util.parseA8(byteValue, index)).append("次;");// 总断相次数
        index = index + 2;
        resultString.append("A相断相次数:").append(ProtocolGW_09Util.parseA8(byteValue, index)).append("次;");// A相断相次数
        index = index + 2;
        resultString.append("B相断相次数:").append(ProtocolGW_09Util.parseA8(byteValue, index)).append("次;");// B相断相次数
        index = index + 2;
        resultString.append("C相断相次数:").append(ProtocolGW_09Util.parseA8(byteValue, index)).append("次;");// C相断相次数
        index = index + 2;
        resultString.append("断相累计时间:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("min;");// 断相累计时间
        index = index + 3;
        resultString.append("A断相累计时间:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("min;");// A断相累计时间
        index = index + 3;
        resultString.append("B断相累计时间:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("min;");// B断相累计时间
        index = index + 3;
        resultString.append("C断相累计时间:").append(ProtocolGW_09Util.parseA10(byteValue, index)).append("min;");// C断相累计时间
        index = index + 3;
        resultString.append("最近一次断相起始时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 最近一次断相起始时刻
        index = index + 4;
        resultString.append("A相最近断相起始时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// A相最近断相起始时刻
        index = index + 4;
        resultString.append("B相最近断相起始时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// B相最近断相起始时刻
        index = index + 4;
        resultString.append("C相最近断相起始时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// C相最近断相起始时刻
        index = index + 4;
        resultString.append("最近一次断相结束时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 最近一次断相结束时刻
        index = index + 4;
        resultString.append("A相最近断相结束时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// A相最近断相结束时刻
        index = index + 4;
        resultString.append("B相最近断相结束时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// B相最近断相结束时刻
        index = index + 4;
        resultString.append("C相最近断相结束时刻:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// C相最近断相结束时刻
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF1718Frame(byte[] byteValue, int index, String type) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA21(byteValue, index)).append(";");// 月冻结类数据时标:yyyy-MM;
        index = index + 2;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append(type).append("有功总电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 正向有功总电能示值:100kWh;
        index = index + 5;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1) + type).append("有功电能示值:").append(String.valueOf(ProtocolGW_09Util.parseA14(byteValue, index))).append("kWh;");// 费率i正向有功电能示值:100kWh;
            index = index + 5;
        }
        resultString.append(type).append("无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 正向无功总电能示值:100kWh;
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1) + type).append("无功电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i正向无功电能示值:100kvarh;
            index = index + 4;
        }
        if (type.equals("正向")) {
            resultString.append("一象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 一象限无功总电能示值:100kvarh;
            index = index + 4;
            for (int i = 0; i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("一象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i一象限无功总电能示值:100kvarh;
                index = index + 4;
            }
            resultString.append("四象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 四象限无功总电能示值:100kWh;
            index = index + 4;
            for (int i = 0; i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("四象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i四象限无功总电能示值:100kvarh;
                index = index + 4;
            }
        } else {
            resultString.append("二象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 一象限无功总电能示值:100kvarh;
            index = index + 4;
            for (int i = 0; i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("二象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i一象限无功总电能示值:100kvarh;
                index = index + 4;
            }
            resultString.append("三象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 四象限无功总电能示值:100kWh;
            index = index + 4;
            for (int i = 0; i < tariffnum; i++) {
                resultString.append("费率").append((i + 1)).append("三象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i四象限无功总电能示值:100kvarh;
                index = index + 4;
            }
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF5678Frame(byte[] byteValue, int index, String type) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append(type).append("总电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kvarh");// 日正向无功总电能量
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("日费率").append((i + 1) + type).append("电能量:").append(ProtocolGW_09Util.parseA13(byteValue, index)).append("kvarh;");// 日费率i正向无功电能量:100kvarh;
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF3F4Frame(byte[] byteValue, int index, String type) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        resultString.append(type).append("有功总最大需量:").append(ProtocolGW_09Util.parseA23(byteValue, index)).append("kW");// 正向有功总最大需量
        index = index + 3;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append(i + type).append("有功最大需量:").append(ProtocolGW_09Util.parseA23(byteValue, index)).append("kW;");// 费率i正向有功最大需量:100kW;
            index = index + 3;
        }
        resultString.append(type).append("有功最大需量发生时间:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 正向有功总最大需量发生时间;
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1) + type).append("有功最大需量发生时间:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 费率i正向有功总最大需量发生时间;
            index = index + 4;
        }
        resultString.append(type).append("无功总最大需量:").append(ProtocolGW_09Util.parseA23(byteValue, index)).append("kvar;");// 正向无功总最大需量:100kvar;
        index = index + 3;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1) + type).append("无功最大需量:").append(ProtocolGW_09Util.parseA23(byteValue, index)).append("kvar;");// 费率i正向无功最大需量:100kvar;
            index = index + 3;
        }
        resultString.append(type).append("无功总最大需量发生时间:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 正向无功总最大需量发生时间;
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            resultString.append("费率").append((i + 1) + type).append("无功最大需量发生时间:").append(ProtocolGW_09Util.parseA17(byteValue, index)).append(";");// 费率i正向无功最大需量发生时间;
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static ReqDataComm parseF1F2Frame(byte[] byteValue, int index, int fn) {
        ReqDataComm reqDataComm = new ReqDataComm();
        StringBuffer resultString = new StringBuffer("");
        resultString.append("日冻结类数据时标:").append(ProtocolGW_09Util.parseA20(byteValue, index)).append(";");// 日冻结类数据时标:yyyy-MM-dd;
        index = index + 3;
        resultString.append("终端抄表时间:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 终端抄表时间:yyyy-MM-dd
        // HH:mm;
        index = index + 5;
        int tariffnum = ProtocolUtils.Unsignd(byteValue[index++]);
        if (tariffnum ==0 || tariffnum > 96) {
            tariffnum = TARIFF_NUM_DEFAULT;
        }
        resultString.append("费率数:").append(tariffnum).append(";");// 费率数:1;
        if (fn == 1) {
            resultString.append("正向有功总电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 正向有功总电能示值:100kWh;
        } else {
            resultString.append("反向有功总电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 正向有功总电能示值:100kWh;
        }
        index = index + 5;
        for (int i = 0; i < tariffnum; i++) {
            if (fn == 1) {
                resultString.append("费率").append((i + 1)).append("正向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 费率i正向有功电能示值:100kWh;
            } else {
                resultString.append("费率").append((i + 1)).append("反向有功电能示值:").append(ProtocolGW_09Util.parseA14(byteValue, index)).append("kWh;");// 费率i正向有功电能示值:100kWh;
            }
            index = index + 5;
        }
        if (fn == 1) {
            resultString.append("正向无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 正向无功总电能示值:100kWh;
        } else {
            resultString.append("反向无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 正向无功总电能示值:100kWh;
        }
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            if (fn == 1) {
                resultString.append("费率").append((i + 1)).append("正向无功电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i正向无功电能示值:100kvarh;
            } else {
                resultString.append("费率").append((i + 1)).append("反向无功电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i正向无功电能示值:100kvarh;
            }
            index = index + 4;
        }
        if (fn == 1) {
            resultString.append("一象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 一象限无功总电能示值:100kvarh;
        } else {
            resultString.append("二象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 一象限无功总电能示值:100kvarh;
        }
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            if (fn == 1) {
                resultString.append("费率").append((i + 1)).append("一象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i一象限无功总电能示值:100kvarh;
            } else {
                resultString.append("费率").append((i + 1)).append("二象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i一象限无功总电能示值:100kvarh;
            }
            index = index + 4;
        }
        if (fn == 1) {
            resultString.append("四象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 四象限无功总电能示值:100kWh;
        } else {
            resultString.append("三象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 四象限无功总电能示值:100kWh;
        }
        index = index + 4;
        for (int i = 0; i < tariffnum; i++) {
            if (fn == 1) {
                resultString.append("费率").append((i + 1)).append("四象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i四象限无功总电能示值:100kvarh;
            } else {
                resultString.append("费率").append((i + 1)).append("三象限无功总电能示值:").append(ProtocolGW_09Util.parseA11(byteValue, index)).append("kvarh;");// 费率i四象限无功总电能示值:100kvarh;
            }
            index = index + 4;
        }
        reqDataComm.setValue(resultString.toString());
        return reqDataComm;
    }

    private static String packTd_cFrame(String data, GwItemData itemData) {
        Req2ndDataParam param = (Req2ndDataParam) itemData.getData();
        data = ProtocolGW_09Util.pickA15(param.getStarttime()) + data;
        data = NumberUtil.num2PadString((int) param.getFreezedensity(), 16, 2, "0") + data;
        data = NumberUtil.num2PadString((int) param.getDatanum(), 16, 2, "0") + data;
        return data;
    }

    private static String packTd_dFrame(String data, GwItemData itemData) {
        Req2ndDataParam param = (Req2ndDataParam) itemData.getData();
        data = ProtocolGW_09Util.pickA20(param.getStarttime()) + data;
        return data;
    }

    private static String packTd_mFrame(String data, GwItemData itemData) {
        Req2ndDataParam param = (Req2ndDataParam) itemData.getData();
        data = ProtocolGW_09Util.pickA21(param.getStarttime()) + data;
        return data;
    }

    /**
     * 曲线类数据时标
     *
     * @param byteValue
     * @param index
     * @return
     */
    private static String curveData(byte[] byteValue, int index) {
        StringBuffer resultString = new StringBuffer("");
        resultString.append("起始时间ts:").append(ProtocolGW_09Util.parseA15(byteValue, index)).append(";");// 起始时间ts：分时日月年
        index = index + 5;
        resultString.append("冻结密度:");
        int freezeTime = ProtocolUtils.Unsignd(byteValue[index++]);// 数据冻结密度m
        if (freezeTime == 0) {
            resultString.append("不冻结;");
        } else if (freezeTime == 1) {
            resultString.append("15 min;");
        } else if (freezeTime == 2) {
            resultString.append("30 min;");
        } else if (freezeTime == 3) {
            resultString.append("60 min;");
        } else if (freezeTime == 254) {
            resultString.append("5 min;");
        } else if (freezeTime == 255) {
            resultString.append("1 min;");
        } else {
            resultString.append("备用;");
        }
        resultString.append("数据点数:").append(ProtocolUtils.Unsignd(byteValue[index++])).append(";");// 数据点数n
        return resultString.toString();
    }
}
